﻿namespace TestApp.Client
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using Contracts;
    using JetBrains.Annotations;
    using MvvmTools;

    internal abstract class EntityViewModel : NotificationModel, IEntityViewModel
    {
        protected EntityViewModel([NotNull] Func<IEntityParamViewModel> paramFactory)
        {
            Contract.Requires<ArgumentNullException>(paramFactory != null);
            Params = new List<IEntityParamViewModel>();
            for (var i = 0; i < EntityDto.ParameterCount; i++)
            {
                Params.Add(paramFactory());
            }
        }

        public abstract string Name { get; }

        public IList<IEntityParamViewModel> Params { get; private set; }

        public void Update(EntityDto dataEntity)
        {
            Contract.Requires<ArgumentNullException>(dataEntity != null);
            for (var paramIndex = 0; paramIndex < dataEntity.Parameters.Length; paramIndex++)
            {
                Params[paramIndex].UdateValue(dataEntity.Parameters[paramIndex]);
            }
        }
    }
}
